package org.jdsm.flow.core.users.impl.gae.objectify;

import com.googlecode.objectify.Ref;
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Index;
import com.googlecode.objectify.annotation.Unindex;
import org.jdsm.flow.core.users.IGroup;

import java.util.ArrayList;
import java.util.List;

/**
 * User: mikom
 * Date: 11/22/12
 * Time: 4:36 PM
 */
@Entity
public class Group implements IGroup<Long> {
    @Id
    private Long id;
    @Index
    private String name;
    @Index
    private Long permission;
    @Unindex
    private String description;

    private List<Ref<User>> users = new ArrayList<Ref<User>>();

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public Long getPermission() {
        return permission;
    }

    @Override
    public String getDescription() {
        return description;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setPermission(Long permission) {
        this.permission = permission;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public List<Ref<User>> getUsers() {
        return users;
    }

    public void setUsers(List<Ref<User>> users) {
        this.users = users;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Group group = (Group) o;

        if (description != null ? !description.equals(group.description) : group.description != null) return false;
        if (id != null ? !id.equals(group.id) : group.id != null) return false;
        if (name != null ? !name.equals(group.name) : group.name != null) return false;
        if (permission != null ? !permission.equals(group.permission) : group.permission != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (permission != null ? permission.hashCode() : 0);
        result = 31 * result + (description != null ? description.hashCode() : 0);
        return result;
    }
}
